from functools import reduce
def add(x,y,f):
    return f(x)+f(y)
print(add(3,-6,abs))

ls1 = list(map(abs,[-1,-2,3,4,5]))
print(ls1)

def mul(x,y):
    return x*y

r = reduce(mul,map(abs,[-1,2,3,4,5]))
#print(r)

def fn(x,y):
    return x*10+y

def char2num(s):
    digits = {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9}
    return digits[s]
#print(reduce(fn, map(char2num, '13579')))



def str2int(s):
    def fn(x, y):
        return x * 10 + y
    def char2num(s):
        return DIGITS[s]
    return reduce(fn, map(char2num, s))

DIGITS = {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9}

#print(str2int('222'))

def toFirstUpper(s):
    return s[0].upper()+s[1:].lower()
print(list(map(toFirstUpper, ['adam', 'LISA', 'barT'])))


def odd(n):
    return n%2==1
ls = [1,2,3,4,5,6,7,8,9]
print(list(filter(odd,ls)))

print(sorted([33,-2,5,11,77,-4],key=abs))



L = [('Bob', 75), ('Adam', 92), ('Bart', 66), ('Lisa', 88)]

def by_score(t):
    return t[1]

def by_name(t):
    return t[0].lower()

L2 = sorted(L, key=by_name)
print(L2)


def inc():
    x = 0
    def fn():
        nonlocal x
        x = x + 1
        return x
    return fn

f = inc()
print(f()) # 1
print(f()) # 2
